[common][flink] Fix missing cast rule for DATE/TIME/TIMESTAMP to bounded CHAR/VARCHAR - #9670
Merged
Merged
Conversation
…ded CHAR/VARCHAR DateToStringCastRule, TimeToStringCastRule and TimestampToStringCastRule registered VarCharType.STRING_TYPE as their target, so CastExecutors only matched a type equal to it. A bounded VARCHAR/CHAR target, or a plain STRING NOT NULL, resolved to no rule, and SchemaManagerUtils rejects the column type change when the executor is null even though DataTypeCasts.supportsCast allows it. Key them on DataTypeFamily.CHARACTER_STRING, which the class javadoc here already claims, and trim or pad through BinaryStringUtils like the numeric and boolean rules. Bounded character targets already truncate and blank pad for the other scalar types, asserted since 47d4dd6.
JingsongLi
reviewed
Sep 11, 2026
JingsongLi
left a comment
Contributor
There was a problem hiding this comment.
The schema-change path currently allows datetime-to-character conversion but cannot resolve an executor for bounded CHAR/VARCHAR targets. The new family-based rules close that mismatch, and their truncation/CHAR padding follows the existing numeric and boolean conversion contract. I also checked null handling in schema reads and the unchanged timestamp/time-zone formatting.
No blocking defect found. All 4 DateTimeToCharacterStringCastRuleTest cases pass with the head rules on JDK 8; I inspected but did not rerun the Flink ALTER TABLE integration case. Tables using the newly supported ALTER need readers with these rules, as older readers cannot perform that conversion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
The three date/time-to-string cast rules target
VarCharType.STRING_TYPE, soCastExecutorsonly matches a type equal to it — a boundedVARCHAR(n)/CHAR(n), or a plainSTRING NOT NULL, resolves to no rule.SchemaManagerUtilstreats a null executor as a rejection even thoughDataTypeCasts.supportsCastallows the change, soALTER TABLE T MODIFY (b VARCHAR(10))on aTIMESTAMP(3)column fails with "cannot be converted to VARCHAR(10) without losing information", while the same statement on anINTcolumn works.Keyed on
DataTypeFamily.CHARACTER_STRINGnow, which the class javadoc of all three already claims, trimming and padding throughBinaryStringUtilslike the numeric and boolean rules. Truncating to a bounded target and blank paddingCHARis existing asserted behaviour for the other scalars (testModifyColumnTypeFromNumericToString, 47d4dd6). This also unblocks Spark'sCAST(<datetime> AS VARCHAR(n))pushdown throughCastTransform, with the truncating semanticsINTalready has.Tests
DateTimeToCharacterStringCastRuleTest, andSchemaChangeITCase.testModifyColumnTypeFromTimestampToBoundedString, which fails on master with the exception above.Written with Claude Code; reasoning and verification are mine.